<?php
/*
 *author:Yangligao
 *Date:2013-10-2
 */
require 'Config.php';
require 'Public/Include/adv.php';
require 'Public/Include/footer.php';
require 'Public/Include/search.php';
$smarty->assign('positionFlag',"我的商品订单");
$flag = $_GET['flag'];
if($flag == 'display'){
	//接收传来的总价
	$totalPrice = $_POST['totalPrice'];
	$smarty->assign('totalPrice',$totalPrice);
	$smarty->display('Index/order.html');
}else if($flag == 'topay'){
// 	Array
// (
//     [form_totalprice] => 209
//     [form_sendway] => 0
//     [form_sendpos] => 22
//     [form_frpid] => ICBC-NET
//     [x] => 70
//     [y] => 20
// )

	//先将订单存入数据库
	//接收传来的数据
	//补齐还差的数据（表单商户订单号，订单的数据，是否已付款，是否审核）
	
	//订单编号
	$formData['form_identy'] = "comming".time();
	//订单的数据 就是cookie中的序列化的值
	$formData['form_data'] = $_COOKIE['myproduct'];
	//订单的总金额
	$formData['form_totalPrice'] = $_POST['form_totalprice'];
	//订单是否已付款
	$formData['form_flag'] = "0";
	//是否是已审查
	$formData['form_adminflag'] = "0";
	//送货方式
	$formData['form_sendway'] =$_POST['form_sendway'];
	//送货地址
	$formData['form_sendpos'] = $_POST['form_sendpos'];
	$formData['form_fahuo'] = '0';
	//表单入库
	$formModel = new FormModel();
	
	$res = $formModel->form_insert($formData);
	
	if($res){
		require 'yeepayCommon.php';
		//入库成功，转接银行
		//拼接易宝支付数据
		
		$p2_Order = $formData['form_identy'];
		$p3_Amt = $formData['form_totalPrice'];
		$p4_Cur = 'CNY';
		$p5_Pid = '';
		$p6_Pcat = '';
		$p7_Pdesc ='';
		$p8_Url ='http://localhost/coming/PayCallback.php';
		$pa_MP = '';
		$pd_FrpId = $_POST['form_frpid'];
		$pr_NeedResponse ='1';
		$hmac = getReqHmacString($p2_Order,$p3_Amt,$p4_Cur,$p5_Pid,$p6_Pcat,$p7_Pdesc,$p8_Url,$pa_MP,$pd_FrpId,$pr_NeedResponse);
		
		$smarty->assign('p0_Cmd',$p0_Cmd);
		$smarty->assign('p1_MerId',$p1_MerId);
		$smarty->assign('p2_Order',$p2_Order);
		$smarty->assign('p3_Amt',$p3_Amt);
		$smarty->assign('p4_Cur',$p4_Cur);
		$smarty->assign('p5_Pid',$p5_Pid);
		$smarty->assign('p6_Pcat',$p6_Pcat);
		$smarty->assign('p7_Pdesc',$p7_Pdesc);
		$smarty->assign('p8_Url',$p8_Url);
		$smarty->assign('p9_SAF',$p9_SAF);
		$smarty->assign('pa_MP',$pa_MP);
		$smarty->assign('pd_FrpId',$pd_FrpId);
		$smarty->assign('pr_NeedResponse',$pr_NeedResponse);
		$smarty->assign('hmac',$hmac);
		
		$smarty->assign('reqURL_onLine',$reqURL_onLine);
		
		$smarty->display('Index/toYee.html');
	}else{
		alertInfo("订单生成失败！", $_SERVER['HTTP_REFERER']);
	}
}



?>
